package com.tvunetworks.center.user.service.impl;

import com.tvunetworks.center.user.mapper.RoleDeviceMapper;
import com.tvunetworks.center.user.model.RoleDevice;
import com.tvunetworks.center.user.service.RoleDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author Etan Yang
 * @data: 2021/4/7 15:53
 * @program: tvucc-aggregator
 * @description:
 */

@Service
@Slf4j
public class RoleDeviceServiceImpl extends BaseService<RoleDevice> implements RoleDeviceService {
    @Autowired
    private RoleDeviceMapper roleDeviceMapper;

    @Override
    public int batchInsert(String roleId, Set<String> peerIds) {
        if (CollectionUtils.isEmpty(peerIds) || StringUtils.isEmpty(roleId)) {
            return 0;
        }
        return roleDeviceMapper.batchInsert(roleId, peerIds);
    }

    @Override
    public void batchDeleteByRoleIdAndPeerIds(String roleId, List<String> peerIds) {
        if (CollectionUtils.isNotEmpty(peerIds)) {
            roleDeviceMapper.batchDeleteByRoleIdAndPeerIds(roleId, peerIds);
        }
    }

    @Override
    public int deleteByRoleId(String roleId) {
        return roleDeviceMapper.deleteByRoleId(roleId);
    }

    @Override
    public List<String> getPeerIdsByRoleId(String roleId) {
        return roleDeviceMapper.getPeerIdsByRoleId(roleId);
    }

    @Override
    public List<RoleDevice> listRoleDeviceByRoleIdAndPeerIds(String roleId, List<String> peerIds) {
        if (CollectionUtils.isEmpty(peerIds)) {
            return new ArrayList<>();
        }
        return roleDeviceMapper.listRoleDeviceByRoleIdAndPeerIds(roleId, peerIds);
    }

    @Override
    public void batchDeleteByIds(List<String> roleDeviceIds) {
        if (CollectionUtils.isNotEmpty(roleDeviceIds)) {
            roleDeviceMapper.batchDeleteByIds(roleDeviceIds);
        }
    }
}
